<?php
$page=isset($_GET['page']) ? $_GET['page'] : 1;

$redis=new Redis();
$redis->connect('127.0.0.1','6379');
$redis=json_encode("week3");
$where="1";
$search="no_type";

$dbh = new PDO('mysql:host=127.0.0.1;dbname=1705phpa', 'root', 'root');
$sql="select * from week3";
$res=$dbh->query($sql);
$data=$res->fetchAll(2);

$count_num=$res->rowCount();//总条数
$size=2;//每页显示条数
$page_count=ceil($count_num/$size);//接收页码
$limit=($page-1)*$size;//计算偏移量

$prev=$page-1>1 ? $page-1 : 1;
$next=$page+1 < $page_count ? $page_count+1 : 1;
$sql="select * from week3 limit $limit,$size";
$arr=$dbh->query($sql);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<body>
<center>

    <table class="layui-table" lay-skin="line">
        <colgroup>
            <col width="150">
            <col width="150">
            <col width="150">
            <col>
        </colgroup>
        <thead>
        <tr><input type="text" class="no_type"><button>查询</button>
            <th>地址</th>
            <th>书本类型</th>
            <th>书本名字</th>
            <th>书本数量</th>
            <th>作者</th>
        </tr>
        <?php
        foreach($arr as $k=>$v)
        {
            echo "<tr><td>$v[no_id]</td><td>$v[no_type]</td><td>$v[no_name]</td><td>$v[no_num]</td><td>$v[no_author]</td></tr>";
        }
        ?>
    </table>

    <a href="show2.php? page=1">首页</a>
    <a href="show2.php? page=<?php echo $prev?>">上一页</a>
    <a href="show2.php? page=<?php echo $next?>">下一页</a>
    <a href="show2.php? page=<?php echo $count_num?>">尾页</a>
</center>
</body>
</html>
